package cn.com.nes.site.action.monitor;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.monitor.FaultService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;

@Controller("fault")
@RequestMapping("/fault")
public class FaultAction {

    @Resource
    private FaultService service;

    //故障概览
    @RequestMapping(method = RequestMethod.POST, value = "/getFaultView")
    public @ResponseBody
    PageData getFaultView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        res = service.getFaultView(reqStatus.getReq());
        return res;
    }

    /**
     * 当前故障列表
     * @param request
     * @param response
     * @param modelMap
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/getFaultList")
    public @ResponseBody
    PageData getFaultList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        res = service.getFaultList(reqStatus.getReq());
        return res;
    }

    /**
     * 故障历史
     * @param request
     * @param response
     * @param modelMap
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/getFaultListDetails")
    public @ResponseBody
    PageData getFaultListDetails(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        res = service.getFaultListDetails(reqStatus.getReq());
        return res;
    }

}
